<template>
  <div>
    <div id="box" v-bind="{style:'height:'+divHeight + 'px'}">
      <li v-for="item in list" ref="lis">
        <img v-lazy="item.albumpic_big">
        <!--<img :src="item.albumpic_big" alt="">-->
        <p>《{{item.songname}}》</p>
        <p>{{item.singername}}</p>
        <div class="smallBox" @click="setId(item.songid)">
          <img src="../../static/img/time1.png" alt="">
        </div>
      </li>
    </div>
  </div>
</template>

<script>
  export default{
    props: ['id'],//接收父组件传递过来的数据
    data(){
      return {
        list: [
//          {
//            albumid: 2062723,
//            albummid: "002PwV2y1kmddb",
//            albumpic_big: "http://i.gtimg.cn/music/photo/mid_album_300/d/b/002PwV2y1kmddb.jpg",
//            albumpic_small: "http://i.gtimg.cn/music/photo/mid_album_90/d/b/002PwV2y1kmddb.jpg",
//            downUrl: "http://dl.stream.qqmusic.qq.com/202345103.mp3?vkey=53601D310CDB719B2BFE348F6CABDF3C0B0DE47A3F9F88DED39D1832B39BD9F54A8F6452E0C429C2FE5A6A3EF097CB13C453F13079385BF7&guid=2718671044",
//            seconds: 236,
//            singerid: 143,
//            singername: "陈奕迅",
//            songid: 202345103,
//            songname: "披风",
//            url: "http://ws.stream.qqmusic.qq.com/202345103.m4a?fromtag=46"
//          },
        ],
      }
    },
    created(){
      this.divHeight = (document.body.clientHeight) - 90 - 32;
      this.getMuisc();
    },
    watch: {
      id: function () {
        this.getMuisc();
      },
      list: function () {
        this.senddate();
      }
    },
    methods: {
      getMuisc(){
//        从本地获取数据，如果本地没有数据，再从后台获取数据
        var sessionId = window.sessionStorage.getItem(this.id);
//        console.log(sessionId);
        if (sessionId != null) {
          this.list = JSON.parse(sessionId);
        } else {
          var url =
            'http://route.showapi.com/213-4?showapi_appid=37413&showapi_sign=b7c3e87eb6354b7f93d93bf0859d6361&topid=' + this.id;
          this.$http.get(url).then(function (response) {
            var result = response.body.showapi_res_body.pagebean.songlist;
            if (result) {
              result.forEach(function (el) {
                if (el.songname.length > 8) {
                  el.songname = el.songname.slice(0, 8);
                  el.songname = el.songname + '...';
                }
                if (el.singername.length > 8) {
                  el.singername = el.singername.slice(0, 8);
                  el.singername = el.singername + '...';
                }
              })
            }
            var Arr = result.slice(0,10);
            Arr = JSON.stringify(Arr);
            window.sessionStorage.setItem(this.id,Arr);
            this.list = result;
          })
        }
      },
      senddate(){
        // 将hello传给父组件
        this.$emit('send', 'true');
      },
      setId(songid){
        this.$emit('sind', songid);
      }
    }
  }
</script>

<style scoped>
  #box {
    /*overflow: hidden;*/
    overflow-y: auto;
  }

  ul {
    margin-top: 0;
    padding-left: 0;
  }

  li {
    float: left;
    width: 50%;
    list-style: none;
    text-align: center;
    position: relative;
  }

  img {
    display: block;
    width: 80%;
    margin: 5px auto;
    border: 1px solid rgba(0, 0, 0, .3);
    box-shadow: 3px 3px 3px rgba(0, 0, 0, .3);
  }

  .smallBox {
    height: 40px;
    width: 80%;
    background-color: rgba(0, 0, 0, .5);
    position: absolute;
    bottom: 67px;
    border-radius: 5px;
    left: 10%;
  }

  .smallBox img {
    position: absolute;
    right: 2%;
    bottom: 5%;
    width: 25px;
    height: 25px;
  }

  .box li > p {
    font-size: 12px;
    margin: 0;
  }

  /*loading动画*/
  .sk-circle {
    width: 40px;
    height: 40px;
    position: fixed;
    left: 50%;
    top: 10%;
  }

  .sk-circle .sk-child {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
  }

  .sk-circle .sk-child:before {
    content: '';
    display: block;
    margin: 0 auto;
    width: 15%;
    height: 15%;
    background-color: #333;
    border-radius: 100%;
    -webkit-animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;
    animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;
  }

  .sk-circle .sk-circle2 {
    -webkit-transform: rotate(30deg);
    -ms-transform: rotate(30deg);
    transform: rotate(30deg);
  }

  .sk-circle .sk-circle3 {
    -webkit-transform: rotate(60deg);
    -ms-transform: rotate(60deg);
    transform: rotate(60deg);
  }

  .sk-circle .sk-circle4 {
    -webkit-transform: rotate(90deg);
    -ms-transform: rotate(90deg);
    transform: rotate(90deg);
  }

  .sk-circle .sk-circle5 {
    -webkit-transform: rotate(120deg);
    -ms-transform: rotate(120deg);
    transform: rotate(120deg);
  }

  .sk-circle .sk-circle6 {
    -webkit-transform: rotate(150deg);
    -ms-transform: rotate(150deg);
    transform: rotate(150deg);
  }

  .sk-circle .sk-circle7 {
    -webkit-transform: rotate(180deg);
    -ms-transform: rotate(180deg);
    transform: rotate(180deg);
  }

  .sk-circle .sk-circle8 {
    -webkit-transform: rotate(210deg);
    -ms-transform: rotate(210deg);
    transform: rotate(210deg);
  }

  .sk-circle .sk-circle9 {
    -webkit-transform: rotate(240deg);
    -ms-transform: rotate(240deg);
    transform: rotate(240deg);
  }

  .sk-circle .sk-circle10 {
    -webkit-transform: rotate(270deg);
    -ms-transform: rotate(270deg);
    transform: rotate(270deg);
  }

  .sk-circle .sk-circle11 {
    -webkit-transform: rotate(300deg);
    -ms-transform: rotate(300deg);
    transform: rotate(300deg);
  }

  .sk-circle .sk-circle12 {
    -webkit-transform: rotate(330deg);
    -ms-transform: rotate(330deg);
    transform: rotate(330deg);
  }

  .sk-circle .sk-circle2:before {
    -webkit-animation-delay: -1.1s;
    animation-delay: -1.1s;
  }

  .sk-circle .sk-circle3:before {
    -webkit-animation-delay: -1s;
    animation-delay: -1s;
  }

  .sk-circle .sk-circle4:before {
    -webkit-animation-delay: -0.9s;
    animation-delay: -0.9s;
  }

  .sk-circle .sk-circle5:before {
    -webkit-animation-delay: -0.8s;
    animation-delay: -0.8s;
  }

  .sk-circle .sk-circle6:before {
    -webkit-animation-delay: -0.7s;
    animation-delay: -0.7s;
  }

  .sk-circle .sk-circle7:before {
    -webkit-animation-delay: -0.6s;
    animation-delay: -0.6s;
  }

  .sk-circle .sk-circle8:before {
    -webkit-animation-delay: -0.5s;
    animation-delay: -0.5s;
  }

  .sk-circle .sk-circle9:before {
    -webkit-animation-delay: -0.4s;
    animation-delay: -0.4s;
  }

  .sk-circle .sk-circle10:before {
    -webkit-animation-delay: -0.3s;
    animation-delay: -0.3s;
  }

  .sk-circle .sk-circle11:before {
    -webkit-animation-delay: -0.2s;
    animation-delay: -0.2s;
  }

  .sk-circle .sk-circle12:before {
    -webkit-animation-delay: -0.1s;
    animation-delay: -0.1s;
  }

  @-webkit-keyframes sk-circleBounceDelay {
    0%, 80%, 100% {
      -webkit-transform: scale(0);
      transform: scale(0);
    }
    40% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }
  }

  @keyframes sk-circleBounceDelay {
    0%, 80%, 100% {
      -webkit-transform: scale(0);
      transform: scale(0);
    }
    40% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }
  }
</style>
